import {formatDate} from "../../../../hrpub/common/utils/utils";

export default class ButtonAction {
    constructor(comp) {
        this.comp = comp;
    }

    // 第一次进页面的按钮状态
    updateButtonStatus = () => {
        const {props} = this.comp;
        const {button, main} = props;
        const {isEdit, orgValue} = main;
        button.setButtonVisible({
            edit: !!(!isEdit && orgValue && orgValue.refpk),
            copy: !!(!isEdit && orgValue && orgValue.refpk),
            save: isEdit,
            cancel: isEdit
        });
    };

    // 按钮点击回调
    headerClick = async (props, btnCode) => {
        const {action} = this.comp;
        const {dispatch} = props;
        switch (btnCode) {
            case 'edit':
                action.tableAct.edit();
                break;
            case 'save':
                action.tableAct.beforeSave();
                break;
            case 'cancel':
                action.tableAct.cancel();
                break;
            case 'copy':
                /*dispatch({
                    type: 'main/update',
                    payload: {
                        copyModalVisible: true
                    }
                });*/
                document.querySelector('#copy-ory-button').click();
                break;
            default:
                break;
        }
    };

    // 人力组织改变
    changeOrg = async (value) => {
        const {props, action} = this.comp;
        const {dispatch} = props;
        await dispatch({
            type: 'main/update',
            payload: {
                orgValue: value
            }
        });
        action.treeAct.getTreeData();
        this.updateButtonStatus();
    };

    closeModal = (key) => {
        const {props} = this.comp;
        const {dispatch} = props;
        dispatch({
            type: 'main/update',
            payload: {
                [key]: false
            }
        });
    };
}